//
//  RegistSetupTwo.m
//  HB
//
//  Created by 孙智慧 on 16/1/27.
//  Copyright © 2016年 孙智慧. All rights reserved.
//

#import "RegistSetupTwo.h"
#import "RegistSetupThree.h"

@implementation RegistSetupTwo

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.lblMobile.text= self.mobileStr;
    CGFloat  heigh =41;
    
    if(IsiPhone6 || IsiPhone6P)
    {
        heigh=41;
    }
    else{
        heigh=35;
    }
    
    
    NSLayoutConstraint* heightConstraint = [NSLayoutConstraint constraintWithItem:self.navImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:heigh];
    
    [self.view addConstraint:heightConstraint];
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //显示导航栏
    [super.navigationController setNavigationBarHidden:NO animated:TRUE];
    //[super.navigationController setToolbarHidden:NO animated:TRUE];
    
    [self setNavigationRight:@"下一步" sel:@selector(nextSteup)];
}

-(void) nextSteup
{
    [self waitingFor:@"正在验证" andMethod:@selector(myTask) onTarget:self];
}

-(void) myTask
{
    locked=YES;
    
    NSString *url= [FxGlobal getServiceUrl:@"user" andFuncName:@"VerifyCode"];
    
    NSString *mobile=self.lblMobile.text;
    
    NSString *code=self.txtCode.text;
    
    NSString *md5Str= [NSString stringWithFormat: @"code=%@&mobile=%@&key=tqa",code,mobile];
    
    NSString *sign = [Common createMD5:md5Str];
    
    NSString *body=[NSString stringWithFormat:@"{\"mobile\":\"%@\",\"code\":\"%@\",\"sign\":\"%@\",\"clicentid\":\"1\"}",mobile,code,sign];
    
    NSDictionary *dictInfo = @{@"url":url,@"body":body};
    
    operation = [[NetWorkOperation alloc] initWithDelegate:self];
    
    [operation setOpInfo:dictInfo];
    
    [operation post];
    
    while (locked) {
        
    }
    
}

-(void) opSuccessForPost:(id)data
{
    operation= nil;
    
    locked= NO;
    
    NSString *dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    
    NSDictionary *data1 = [dataStr objectFromJSONString];
    
    NSString *v=[data1 objectForKey:@"result"];
    
    if([v isEqualToString:@"1"])
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            //打开下一页
            RegistSetupThree *registSetuoThree= [[RegistSetupThree alloc] init];
            
            [self.navigationController  pushViewController:registSetuoThree animated:YES];
        });
    }
    else
    {
        dispatch_sync(dispatch_get_main_queue(), ^{
            [Common showMsg:@"验证码校验失败！" andCancel:YES andHost:self];
        });
    }
}

@end
